package com.xiaoxu.common.exception;

import com.xiaoxu.spzx.model.vo.common.Result;
import com.xiaoxu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName:GlobalExceptionHandler
 * Description:
 *
 * @author: 徐廷泉
 * @Create 2024/1/14 13:43
 */

@ControllerAdvice
public class GlobalExceptionHandler {
    // 全局处理异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result  error(Exception e ){

        e.printStackTrace();

        return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }



        // 自定义异常处理
        @ExceptionHandler(XiaoXuException.class)
        @ResponseBody
        public Result error(XiaoXuException e){

            return Result.build(null , ResultCodeEnum.LOGIN_ERROR) ;
        }
    }

